<template>
  <view>
    <uni-list :border="true">
      <uni-list-item v-for="item in purseWaterList" :key="item.id" :title="item.moneyStr" :note="item.typeStr"
                     :rightText="item.createTime" :thumb="item.thumb" thumb-size="lg"/>
    </uni-list>
    <uni-load-more :status="status" :icon-size="14" :content-text="contentText"/>
  </view>
</template>

<script>
import store from "@/store";
import {listH5Water} from "@/api/qd/water";

export default {
  data() {
    return {
      status: 'more',
      totalCount: 0,
      params: {
        pageNum: 1,
        pageSize: 50,
        userId: store.getters.userId
      },
      contentText: {
        contentdown: "上拉显示更多",
        contentrefresh: "正在加载...",
        contentnomore: "没有更多数据了"
      },
      purseWaterList: []
    }
  },
  onLoad() {
    this.getList()
  },
  methods: {
    //获取列表
    async getList() {
      let data = [{
        // 生成随机5位数随机id
        id: Math.floor(Math.random() * 100000),
        title: '+50',
        note: '钱包自助充值',
        rightText: '2020-02-02 20:20',
        thumb: '/static/images/purse/income.png',
      }];

      listH5Water(this.params).then(res => {
        this.totalCount = res.total;
        if (this.params.pageNum === 1) {
          this.purseWaterList = res.rows
        } else {
          this.purseWaterList = this.purseWaterList.concat(res.rows);
        }

        if (this.params.pageNum * this.params.pageSize >= this.totalCount) {
          this.status = 'no-more';
        } else {
          this.params.pageNum++;
        }
      })
    },
    // 触底加载
    onReachBottom() {
      if (this.status !== 'no-more') {
        this.status = 'loading';
        this.getList()
      } else {
        this.status = "no-more"
      }
    },
    // 上拉刷新
    onPullDownRefresh() {
      console.log('refresh');
      this.purseWaterList = [];
      this.params.pageNum = 1;
      this.status = 'more';
      this.getList();
      uni.stopPullDownRefresh();
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
